package com.tjw.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.tjw.dao.OrderSettingDao;
import com.tjw.pojo.OrderSetting;
import com.tjw.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @author tjw
 * @Date 2020/10/10
 */
@Service
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void add(List<OrderSetting> orderSettingList) {
        if (orderSettingList != null && orderSettingList.size() > 0) {
            for (OrderSetting orderSetting : orderSettingList) {
                Long count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
                if (count > 0) {
                    orderSettingDao.edit(orderSetting);
                } else {
                    orderSettingDao.add(orderSetting);
                }
            }
        }
    }

    @Override
    public List<Map<String, Object>> getOrderSettingByMonth(String month) {
        return orderSettingDao.getOrderSettingByMonth(month);
    }

    @Override
    public void editOrderSettingByDate(OrderSetting orderSetting) {
        Long count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
        if (count > 0) {
            orderSettingDao.edit(orderSetting);
        } else {
            orderSettingDao.add(orderSetting);
        }
    }
}
